# ============================================================================
# 
#  __init__.py
#  KnowledgeEngine
#  
#  Created by John Meredith on 2007-02-20.
#  Copyright 2007 Faulkner Technologies. All rights reserved.
# 
# ============================================================================


# ============================================================================
# Zope Library Imports
from Products.KnowledgeEngine.Common import getProductDirectory

# ============================================================================
# Python Library Imports
import os

# ============================================================================
# Knowledge Engine Library Imports

# ============================================================================
# Python Logging Configuration
# ============================================================================
import logging
log = logging.getLogger("KnowledgeEngine.Startup")

    
# ============================================================================
# Import the KnowledgeEngine portlets
#
# Each KnowledgeEngine portlet type resides in an independant package
# (named after the element type) within the Portlets folder
# in the KnowledgeEngine Zope Product
#
# By individually importing each Portlet type, they have a chance of
# performing their own initialisation, including appropriately
# registering themselves as part of the KnowledgeEngine product.
# ============================================================================

# The path to the KnowledgeEngine Portlet Packages
PORTLETS_PATH = getProductDirectory() + os.sep + "Portlets"

# Dynamically import each of the defined EntitySources packages in the ENTITY_SOURCES_PATH
for portlet in [file for file in os.listdir(PORTLETS_PATH) if os.path.isdir(PORTLETS_PATH + os.sep + file)]:

    # Import the current portlet (if it doesn't contain a .)
    if portlet.find(".") < 0:
        log.info("Registering Portlet: " + portlet)

        exec "from Products.KnowledgeEngine.Portlets." + portlet + " import *"
